package com.wy.springbootblog.controller;

import com.wy.springbootblog.pojo.Result;
import com.wy.springbootblog.pojo.SearchBean;
import com.wy.springbootblog.pojo.Tag;
import com.wy.springbootblog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author work
 */
@RestController
@RequestMapping("/tag")
public class TagController {

    @Autowired
    private TagService tagService;

    // 新增标签
    @PostMapping("/add")
    public Result<Void> add(@RequestBody @Validated Tag tag) {
        return tagService.saveTag(tag);
    }

    // 删除标签
    @DeleteMapping("/delete/{id}")
    public Result<Void> delete(@PathVariable @NotNull Integer id) {
        return tagService.deleteTag(id);
    }

    // 分页查询标签
    @PostMapping("/list")
    public Result<List<Tag>> list(@RequestBody SearchBean<Tag> searchBean) {
        return tagService.tagList(searchBean);
    }

    // 更新标签
    @PostMapping("/update")
    public Result<Void> update(@RequestBody @Validated Tag tag) {
        return tagService.updateTag(tag);
    }
}
